<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Window对象</title>
    <script type="text/javascript">
        //切换成on的图片
        function on(){
            //通过dom对象 获取id
            document.getElementById('img').src = '../img/on.gif';
        }
        //切换成off的图片
        function off(){
            //通过dom对象 获取id
            document.getElementById('img').src = '../img/off.gif';
        }

        var count = 0;
        //使用定时器
        setInterval(function (){
            if (count % 2 == 0){
                on();
            }else{
                off()
            }
            count++;
        },1000);
    </script>
</head>
<body>
     <input  type="button" onclick="on()"  value="开灯"/>
     <img id="img" src="../img/off.gif" />
     <input  type="button" onclick="off()" value="关灯"/>

</body>
</html>